<?php

namespace app\advertisement\controller;

use app\common\controller\DBase;
use think\facade\Db;
use app\advertisement\logic\ApiAdvaccountLogic;
use Throwable;

class ApiAdvaccount extends DBase
{
    /**
     * 模型
     * @var object
     * @phpstan-var ApiAdvaccountModel
     */
    protected object $model;

    public function initialize(): void
    {
        parent::initialize();
    }

    /**
     * 获取list
     * @throws Throwable
     */
    public function ApiAdvaccountsList()
    {
        $params     = $this->request->post();
        $AdvaccountLogic = new ApiAdvaccountLogic();
        return $AdvaccountLogic->getApiAdvaccountsList($params);
    }

    /**
     * 更新之前的广告花费
     * @throws Throwable
     */
    public function IntegratedList()
    {
        $params     = $this->request->get();
        $AdvaccountLogic = new ApiAdvaccountLogic();
        return $AdvaccountLogic->IntegratedList($params);
    }

    /**
     * 统计每日广告运营花费
     * @throws Throwable
     */
    public function CalculateDailyAdvExpenses()
    {
        $params     = $this->request->get();
        $AdvaccountLogic = new ApiAdvaccountLogic();
        return $AdvaccountLogic->CalculateDailyAdvExpenses($params);
    }
    
    /**
     * 临时任务
     * @throws Throwable
     */
    public function TemporaryTasks()
    {
        $params     = $this->request->get();
        $AdvaccountLogic = new ApiAdvaccountLogic();
        return $AdvaccountLogic->TemporaryTasks($params);
    }

    /**
     * 达人视频业绩
     * @throws Throwable
     */
    public function ExpertVideo()
    {
        $params     = $this->request->get();
        $AdvaccountLogic = new ApiAdvaccountLogic();
        return $AdvaccountLogic->ExpertVideo($params);
    }

    /**
     * 剪辑视频业绩
     * @throws Throwable
     */
    public function EditingVideo()
    {
        $params     = $this->request->get();
        $AdvaccountLogic = new ApiAdvaccountLogic();
        return $AdvaccountLogic->EditingVideo($params);
    }

    /**
     * test
     * @throws Throwable
     */
    public function test()
    {
        $advertising = Db::name('gettrackinfo_copy3')
            ->where('time','<',1)
            ->limit(200)
            ->select()
            ->toarray();
        foreach ($advertising as $k=>$v) {
            $order_statement = Db::name('order_statement')
                ->where('transaction_id',$v['number'])
                ->order('updatetime asc')
                ->find();
            if(!empty($order_statement)){
                Db::name('order_statement')
                    ->where('id',$order_statement['id'])
                    ->delete();
            }
            
            $update['time'] = time();
            $advertising = Db::name('gettrackinfo_copy3')
                ->where('id',$v['id'])
                ->update($update);
        }
        return 1;
    }

}
